container_aria

my file learn about tech container (docker, podman, kubernetes)


Project maintained by ariafatah0711 Hosted on GitHub Pages — Theme by mattgraham

ansible conditionals

ansible facts

variblae in gather_facts

ansible node_docker -m setup
ansible node_docker -m setup | grep family
#         "ansible_os_family": "Debian",

ansible node_docker -m setup | grep processor_core
#        "ansible_processor_cores": 6,

ansible node_docker -m setup | less
# /memory
# "ansible_memory_mb": {
#             "real": {
#                "total": 7563
#            },....},

example

---
- name: Playbook setup web server
  hosts: node_docker
  become: true
  gather_facts: true # defaultnya memang true
  vars: # mendefinisikan variable
    user_app: ansibleweb
  tasks:

    ## Install nginx
    - name: Install nginx (Debian)
      ansible.builtin.apt:
        name: nginx
        state: present
      when:
        - ansible_os_family == "Debian"
        - ansible_processor_cores >= 1 or ansible_memory_mb.real.total >= 512
    - name: Install nginx (Alpine)
      community.general.apk:
        name: nginx
        state: present
      when:
        - ansible_os_family == "Alpine"
        - ansible_processor_cores >= 1 or ansible_memory_mb.real.total >= 512

    ## Buat user
    - name: Buat user (Debian) 
      ansible.builtin.user:
        name: ""
        password: belajaransible
        shell: /bin/bash
      when:
        - ansible_os_family == "Debian"
    - name: Buat user (Alpine) 
      ansible.builtin.user:
        name: ""
        password: belajaransible
        shell: /bin/sh
      when:
        - ansible_os_family == "Alpine"

    ## Copy file html
    - name: Copy file html (Debian)
      ansible.builtin.copy:
        src: ./web/
        dest: /var/www/html/
        mode: '604'
        owner: ""
        group: ""
      when:
        - ansible_os_family == "Debian"
    - name: Copy file html (Alpine)
      ansible.builtin.copy:
        src: ./web/
        dest: /usr/share/nginx/html
        mode: '604'
        owner: ""
        group: ""
      when:
        - ansible_os_family == "Alpine"